package it.koutifaris.travianmap.view.mainview;

import it.koutifaris.travianmap.command.Command;
import it.koutifaris.travianmap.context.HasApplicationContex;
import it.koutifaris.travianmap.dal.TravianServerService;
import it.koutifaris.travianmap.dal.TravianServerService.TravianServer;
import it.koutifaris.travianmap.view.serversettingsview.ServerSettingsActivity;
import it.koutifaris.travianmap.view.serversview.ServersActivity;

import java.util.List;

class OpenServersViewCommand extends HasApplicationContex implements Command {

	@Override
	public void execute() {
		List<TravianServer> listServers = getServerList();

		if (listServers.size() == 0) {
			ServerSettingsActivity.startActivity(getActivity());
		} else {
			ServersActivity.startActivity(getActivity());
		}

	}

	private List<TravianServer> getServerList() {
		TravianServerService service = getTravianMapContext().getServerServiceFactory().travianServerService();
		List<TravianServer> listServers = service.listServers();
		service.close();

		return listServers;
	}
}
